package com.tender.kafka;

import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Component;

@Component
public class ConsumerListener {

    /**
     * 本地搭建的环境已经创建的topic 有如下：
     *
     * my-topic1
     * my-topic2
     * topic1
     * topic2
     * tender1
     * tender2
     */


    @KafkaListener(topics = "my-topic2")
    public void onMessage(String message) {
        System.out.println("被消费的消息: " + message);
    }

    @KafkaListener(topics = "my-topic1")
    public void onMessage(String message, Acknowledgment ack) {
        System.out.println("被消费的消息: " + message);
        // 手动提交 ack
        ack.acknowledge();
    }

}
